#include "uniEdge.hpp"
#include "uniMesh.hpp"
#include "rectMeshFunctions.hpp"
#include "exceptions.hpp"

namespace hms {


UniEdge::UniEdge( const UniMesh& mesh, Index index ) :
	StructEdgeBase<UniEdge>( mesh, index )
{}

auto UniEdge::intersectionImp() const -> Vector2s {
	return midpoint();
}

auto UniEdge::normalImp() const -> NormalVector {
	return rectEdgeNormal(m_range);
}


auto UniEdge::lengthImp() const -> scalar {
	if (m_range == EdgeRange::horizontal)
		return m_mesh.dx();
	else
		return m_mesh.dy();
}

auto UniEdge::midpointImp() const -> Vector2s {
	if (m_range == EdgeRange::horizontal)
		return {
			(m_index % m_mesh.nCellsX() + 0.5)*m_mesh.dx(),
			(m_index / m_mesh.nCellsX()      )*m_mesh.dy()
		};
	else
		return {
			(m_modIndex % (m_mesh.nCellsX()+1)      )*m_mesh.dx(),
			(m_modIndex / (m_mesh.nCellsX()+1) + 0.5)*m_mesh.dy()
		};
}

} // end namespace hms